package com.example.synchronizeddemo;

import android.util.Log;

public class Person {
    private String name;

    public Person(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void speak() {
        for (int i = 0; i <= 5; i++) {
            Log.e(getName(), "speak: " + i +  "次" + "Thread" + Thread.currentThread().getName() + "/ time:" + System.currentTimeMillis());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void speaksynchronized() {
        for (int i = 0; i <= 5; i++) {
            Log.e(getName(), "speak: " + i +  "次" + "Thread" + Thread.currentThread().getName() + "/ time:" + System.currentTimeMillis());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
